import store from '../store';
import storage from '@/utils/storage'
import constant from '@/utils/constant'
class Routine 
{
	constructor() {
	    this.scopeUserInfo = 'scope.userInfo';
	}
	
	async getCode(){
		let provider = await this.getProvider();
		return new Promise((resolve,reject)=>{
			uni.login({
				provider:provider,
				success(res) {
					if (res.code) 
					return resolve(res.code);
				},
				fail(){
					return reject(null);
				}
			})
		})
	}
	
	/**
	 * 获取服务供应商
	 */
	getProvider()
	{
		return new Promise((resolve,reject)=>{
			uni.getProvider({
				service:'oauth',
				success(res) {
					resolve(res.provider);
				},
				fail() {
					resolve(false);
				}
			});
		});
	}
	
	/**
	 * 调起订阅界面
	 * array tmplIds 模板id
	 */
	subscribe(tmplIds) {
		 let wecaht = wx;
		return new Promise((reslove, reject) => {
			wecaht.requestSubscribeMessage({
				tmplIds: tmplIds,
				success(res) {
					return reslove(res);
				},
				fail(res) {
					return reslove(res);
				}
			})
		});
	}
	
	
}

export default new Routine();